package com.bootdo.wx.controller;

import com.bootdo.wx.domain.GoodsTagLinkDO;
import com.bootdo.wx.service.GoodsTagLinkService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品标签关联表
 * 
 * @author sys
 * @email 1992lcg@163.com
 * @date 2019-03-19 16:39:22
 */
 
@Controller
@RequestMapping("/wx/goodsTagLink")
public class GoodsTagLinkController {
	@Autowired
	private GoodsTagLinkService goodsTagLinkService;
	
	@GetMapping()
	@RequiresPermissions("wx:goodsTagLink:goodsTagLink")
	String GoodsTagLink(){
	    return "wx/goodsTagLink/goodsTagLink";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wx:goodsTagLink:goodsTagLink")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<GoodsTagLinkDO> goodsTagLinkList = goodsTagLinkService.list(query);
		int total = goodsTagLinkService.count(query);
		PageUtils pageUtils = new PageUtils(goodsTagLinkList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wx:goodsTagLink:add")
	String add(){
	    return "wx/goodsTagLink/add";
	}

	@GetMapping("/edit/{goodsId}")
	@RequiresPermissions("wx:goodsTagLink:edit")
	String edit(@PathVariable("goodsId") String goodsId,Model model){
		GoodsTagLinkDO goodsTagLink = goodsTagLinkService.get(goodsId);
		model.addAttribute("goodsTagLink", goodsTagLink);
	    return "wx/goodsTagLink/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wx:goodsTagLink:add")
	public R save( GoodsTagLinkDO goodsTagLink){
		if(goodsTagLinkService.save(goodsTagLink)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wx:goodsTagLink:edit")
	public R update( GoodsTagLinkDO goodsTagLink){
		goodsTagLinkService.update(goodsTagLink);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wx:goodsTagLink:remove")
	public R remove( String goodsId){
		if(goodsTagLinkService.remove(goodsId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wx:goodsTagLink:batchRemove")
	public R remove(@RequestParam("ids[]") String[] goodsIds){
		goodsTagLinkService.batchRemove(goodsIds);
		return R.ok();
	}
	
}
